package com.lst.tools.wx.smallroutine.properties;

import com.lst.tools.wx.smallroutine.constants.WxSmallRoutineEnum;
import com.lst.tools.wx.smallroutine.vo.SmallRoutineEncryptedDataParam;
import com.lst.tools.wx.smallroutine.vo.WxCatchBasicAccessTokenParam;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 芝麻认证配置参数
 *
 * @author: Frank
 * @date: 2019/09/24 13:51
 * @version: V1.0
 */
@ToString
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "wxSubscribe")
public class WxSmallRoutineProperties {

    /**
     * appId 占位符
     */
    @Setter
    private String appIdPlaceholder = WxSmallRoutineEnum.APP_ID_PLACEHOLDER.getValue();
    /**
     * appSecret 占位符
     */
    @Setter
    private String appSecretPlaceholder = WxSmallRoutineEnum.APP_SECRET_PLACEHOLDER.getValue();

    /**
     * accessToken占位符
     */
    @Setter
    private String accessTokenPlaceholder = WxSmallRoutineEnum.ACCESS_TOKEN_PLACEHOLDER.getValue();

    /**
     * code 占位符
     */
    @Setter
    private String codePlaceholder = WxSmallRoutineEnum.CODE_PLACEHOLDER.getValue();

    /**
     * 获取普通access token url
     */
    @Setter
    private String catchBasicAccessTokenUrl = WxSmallRoutineEnum.CATCH_BASIC_ACCESS_TOKEN_URL.getValue();
    /**
     * 获取普通access token url
     */
    @Setter
    private String catchSmallRoutineQRCodeUrlUrl = WxSmallRoutineEnum.CATCH_SMALL_ROUTINE_QR_CODE_URL.getValue();
    /**
     * 获取小程序登录 url
     */
    @Setter
    private String smallRoutineLoginUrl = WxSmallRoutineEnum.SMALL_ROUTINE_LOGIN_URL.getValue();
    /**
     * 发送模板消息 url
     */
    @Setter
    private String sendTemplateMessageUrl = WxSmallRoutineEnum.SEND_TEMPLATE_MESSAGE_URL.getValue();


    public String getCatchBasicAccessTokenUrl(WxCatchBasicAccessTokenParam wxCatchBasicAccessTokenParam) {
        return this.catchBasicAccessTokenUrl
                .replace(this.appIdPlaceholder, wxCatchBasicAccessTokenParam.getAppId())
                .replace(this.appSecretPlaceholder, wxCatchBasicAccessTokenParam.getSecret());
    }

    public String getCatchSmallRoutineQRCodeUrlUrl(String basicAccessToken) {
        return this.catchSmallRoutineQRCodeUrlUrl
                .replace(this.accessTokenPlaceholder, basicAccessToken);
    }

    public String getSmallRoutineLoginUrl(SmallRoutineEncryptedDataParam smallRoutineEncryptedDataParam) {
        return this.smallRoutineLoginUrl
                .replace(this.appIdPlaceholder, smallRoutineEncryptedDataParam.getAppId())
                .replace(this.appSecretPlaceholder, smallRoutineEncryptedDataParam.getSecret())
                .replace(this.codePlaceholder, smallRoutineEncryptedDataParam.getCode());
    }

    public String getSendTemplateMessageUrl(String basicAccessToken) {
        return this.sendTemplateMessageUrl
                .replace(this.accessTokenPlaceholder, basicAccessToken);
    }
}
